import 'package:flutter_app/db/hi_cache.dart';
import 'package:flutter_app/http/core/hi_net.dart';
import 'package:flutter_app/http/request/base_request.dart';
import 'package:flutter_app/http/request/login_request.dart';
import 'package:flutter_app/http/request/registration_request.dart';

class LoginDao {
  static login(String userName, String password) {
    return _send(userName, password);
  }
  static register(String userName, String password,String imoocId,String orderId) {
    return _send(userName, password,imoocId:imoocId,orderId:orderId);
  }



  static _send(String userName, String password, {imoocId, orderId}) async {
    BaseRequest request;
      if(imoocId!=null&&orderId!=null) {
          request=RegistrationRequest();
      }else{
        request=LoginRequest();
      }
      request
          .add("username", userName)
          .add("password", password);
      var result=await HiNet.getInstance().fire(request);
      ///登录成功保存token
     /* if(result['code']==0&& result['data']!=null){
        HiCache.getInstance().setString("token", "");
      }*/
      return result;
  }
  static getBoardingPass(){
    return HiCache.getInstance().get("token");
  }
}
